//
//  RBChangeNickNameVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/7/15.
//

#import "RBChangeNickNameVC.h"
#import <UIColor+YYAdd.h>
#import "RBThemeConfig.h"
#import <UIControl+YYAdd.h>
#import "UIView+RBAdd.h"
#import "RBDefine.h"
#import <Masonry.h>
#import "UIButton+RBAdd.h"
#import "RBProfileVC.h"
#import "UIScrollView+RBAdd.h"
#import "RBTextField.h"
#import "UIViewController+RBAdd.h"

@interface RBChangeNickNameVC ()

@property(nonatomic, strong)UIView *contentView;
@property(nonatomic, strong)RBTextField *textF;
@property(nonatomic, strong)UIButton *confirmBtn;

@end

@implementation RBChangeNickNameVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.title = @"更换昵称";
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem.alloc initWithImage:[[UIImage imageNamed:@"settingQuestion"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(questionBtnTapped)];
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:nil forState:UIControlStateNormal];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    self.contentView.hidden = NO;
    self.confirmBtn.hidden = NO;
}

#pragma mark - Network

#pragma mark - Event

- (void)questionBtnTapped
{
    
}

- (void)confirmBtnTapped
{
    __weak typeof(self) weak_self = self;
    if(!self.textF.text.length)
    {
        [self.view showTip:@"请输入昵称" completion:nil];
        return;
    }
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"nickname"] = self.textF.text;
    } path:@"hu_nickname_save" post:YES log:YES responseClass:RBResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(id data) {
        [weak_self.navigationController popViewControllerAnimated:YES];
    } failBlock:^(RBResponse *data) {
        [weak_self.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Setter

#pragma mark - Getter

- (UIView *)contentView
{
    if (!_contentView)
    {
        self.contentView = ({
            UIView *view = UIView.new;
            view.backgroundColor = UIColor.whiteColor;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(Zoom(10));
                make.left.right.mas_equalTo(0);
                make.height.mas_equalTo(Zoom(63));
            }];
            
            RBTextField *textF = RBTextField.new;
            textF.font = [UIFont systemFontOfSize:Zoom(14)];
            textF.textColor = [RBThemeConfig textBlackColor];
            textF.placeholder = @"请输入新昵称";
            textF.text = self.name;
            self.textF = textF;
            [view addSubview:textF];
            [textF mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo(Zoom(18));
                make.right.mas_equalTo(Zoom(-18));
            }];
            
            view;
        });
    }
    return _contentView;
}

- (UIButton *)confirmBtn
{
    if (!_confirmBtn)
    {
        self.confirmBtn = ({
            UIButton *view = UIButton.new;
            [view rbAddTarget:self action:@selector(confirmBtnTapped)];
            [view rbSetTitle:@"确认修改"];
            [view rbSetTitleColor:UIColor.whiteColor];
            [view rbSetFont:[UIFont systemFontOfSize:Zoom(15)]];
            [view rbSetCornerRadius:Zoom(22)];
            view.backgroundColor = [UIColor colorWithHexString:@"#518CFF"];
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(-MAX(Zoom(25), kRBSafeBottomHeight));
                make.centerX.mas_equalTo(0);
                make.size.mas_equalTo(CGSizeMake(Zoom(339), Zoom(44)));
            }];
            view;
        });
    }
    return _confirmBtn;
}

@end
